var e = getApp();

Component({
    properties: {
        datasource: {
            type: Array
        },
        orderType: {
            type: String
        },
        detailUrl: {
            type: String
        },
        status: {
            type: Number
        }
    },
    data: {
        language: "",
        regional: "请选择快递公司",
        dateshow_1: !1,
        columns: [],
        checkList: [],
        orderPayId: "",
        options: [],
        dialogVisible: !1,
        expressName: "",
        numberName: "",
        addresseeInfo: {},
        showQrcode: !1,
        qrcode_url: "",
        sendGoogsFail: {
            show: !1,
            msg: ""
        },
        showID: "",
        jurisdiction_set: 0,
        showBarter: !1,
        showBarter_value: null
    },
    lifetimes: {
        attached: function() {
            var e = wx.getStorageSync("langIndex");
            this.setData({
                language: e.en
            });
        },
        moved: function() {},
        detached: function() {}
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        toStore: function(e) {
            var t = e.currentTarget.dataset.order;
            92 == t.plugin_id ? wx.navigateTo({
                url: "/packageA/member/supplier/SupplierShop/SupplierShop?id=" + t.id + "&fromOrder=1"
            }) : 31 == t.plugin_id || 32 == t.plugin_id ? wx.navigateTo({
                url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + t.id + "&fromOrder=1"
            }) : 0 == t.plugin_id && wx.reLaunch({
                url: "/packageG/index/index"
            });
        },
        showMore: function(e) {
            var t = e.currentTarget.dataset.order.order_sn;
            this.data.showID == t ? this.setData({
                showID: ""
            }) : this.setData({
                showID: t
            });
        },
        getTemplate: function(t, a) {
            var r = e.getNetAddresss("member.member.getMiniTemplateCorrespond"), o = this;
            e._getNetWork({
                url: r,
                data: {
                    small_type: 2
                },
                success: function(e) {
                    var r = e.data;
                    if (1 == r.result) {
                        for (var i = [], s = 0; s < r.data.length; s++) i.push(r.data[s].template_id);
                        o.setData({
                            TemplateArray: i
                        }), wx.requestSubscribeMessage({
                            tmplIds: o.data.TemplateArray,
                            success: function(e) {
                                o._toRefund(t, a);
                            },
                            fail: function() {
                                o._toRefund(t, a);
                            }
                        });
                    } else wx.showToast({
                        title: r.msg,
                        icon: "none",
                        duration: 1500
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        multiplePayChange: function(e) {
            this.setData({
                checkList: e.detail
            }), this.triggerEvent("MultiplePayNotification", this.data.checkList);
        },
        goOrderdetail: function(e) {
            var t = this.data.orderType, a = e.currentTarget.dataset.orderid;
            wx.navigateTo({
                url: "/packageA/member/orderdetail/orderdetail?order_id=" + a + "&orderType=" + t
            });
        },
        operation: function(e) {
            var t = e.currentTarget.dataset.item, a = e.currentTarget.dataset.order, r = e.currentTarget.dataset.orderidx;
            if (this.setData({
                orderPayId: a.id
            }), t.api || 41 == t.value) if (console.log(t), 8 == t.value) this._checklogistics(a, t); else if (12 == t.value) this._deleteOrder(a, t, r); else if (10 == t.value) this._comment(a, t); else if (1 == t.value || "snatch_regiment_pay" == t.value) this._toPay(a, t); else if (13 == t.value || "snatch_regiment_refund" == t.value) {
                this.getTemplate(a, t);
            } else 9 == t.value ? this._cancleOrder(a, t, r) : 5 == t.value ? this._confirmOrder(a, t) : 18 == t.value ? this._toRefundDetail(a, t) : "cashierPay" == t.value ? this._cashPayOrder(a, t) : "verification_code" == t.value ? this._verification(a, t) : 20 == t.value ? this._verificationCash(a, t) : 21 == t.value ? wx.navigateTo({
                url: "/packageD/member/myOrder/order_record/order_record?order_id=" + item.id
            }) : 22 == t.value ? this._payMoney(a, t) : 101 == t.value ? wx.navigateTo({
                url: "/packageE/pickUpCard/pickUpCardReimburse/pickUpCardReimburse?orderid=" + a.id
            }) : "coupon" == t.value ? (console.log(a.id), wx.navigateTo({
                url: "/packageD/coupon_share/coupon_share?orderid=" + a.id
            })) : 23 == t.value || 60 == t.value ? (3 == a.dispatch_type_id ? this.sendGoogs() : (this._getCompany(), 
            this.setData({
                dialogVisible: !0
            })), this.triggerEvent("stoprefresh", !0), this.setData({
                expressName: "",
                numberName: ""
            })) : 24 == t.value || 61 == t.value ? this._deliverGoodsCancel(a, t) : 25 == t.value ? this._collectGoods(a, t) : 26 == t.value ? this._closeOrderPay(a, t) : 27 == t.value ? this._evaluate(a, t) : 28 == t.value ? this._truckList(t, a) : 41 == t.value || (50 == t.value ? this._checkInvoice(t, a) : 11 == t.value ? this.confirmHotelOrder(t.api, a.id) : "lease_toy_refund" == t.value || "package_deliver_clerk" == t.value ? (console.log("申请归还"), 
            this.getRuruen(t, a)) : "lease_toy_apply_adopt" == t.value ? (console.log("填写归还"), 
            wx.navigateTo({
                url: "/packageB/member/OrderReturn/OrderReturn?id=" + a.id
            })) : "lease_toy_return_info" == t.value ? (console.log("归还详情"), wx.navigateTo({
                url: "/packageA/others/order_ruturn_info/order_ruturn_info?id=" + a.id
            })) : "package_deliver" == t.value ? (console.log("自提点核销"), console.log(t.api), 
            this.getQrImg(t, a)) : "expediting_delivery" == t.value ? this.publicMessage(t, a, "提醒商家发货") : "snatch_regiment_barter" == t.value ? this.setData({
                showBarter: !0,
                showBarter_value: a.barter
            }) : this.publicMessage(t, a, t.name)); else "expediting_delivery" == t.value ? wx.showToast({
                icon: "none",
                title: "已提醒过商家",
                duration: 1e3
            }) : wx.showToast({
                icon: "none",
                title: "error:错误4008820",
                duration: 1e3
            });
        },
        confirmBarter: function() {
            var t = e.getNetAddresss("plugin.snatch-regiment.api.order.barter");
            t += "&order_id=" + this.data.orderPayId, e._getNetWork({
                url: t,
                success: function(e) {
                    var t = e.data;
                    1 == t.result ? (wx.showToast({
                        title: "易货兑换成功",
                        icon: "success",
                        duration: 1500,
                        success: function() {}
                    }), that.getdata()) : wx.showToast({
                        icon: "none",
                        title: t.msg,
                        duration: 1200
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        cancelBarter: function() {
            this.setData({
                showBarter: !1,
                showBarter_value: null
            });
        },
        getQrImg: function(t, a) {
            var r = this, o = e.getNetAddresss(t.api);
            "package_deliver" == t.value ? o += "&order_id=" + a.id : o += "&order_pay_id=" + a.id, 
            e._getNetWork({
                url: o,
                success: function(e) {
                    var t = e.data;
                    1 == t.result ? r.setData({
                        showQrcode: !0,
                        qrcode_url: t.data.qr_code_url
                    }) : wx.showToast({
                        icon: "none",
                        title: t.msg,
                        duration: 1e3
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        publicMessage: function(t, a, r) {
            var o = this;
            t.api && wx.showModal({
                title: "提示",
                content: "确定".concat(r, "?"),
                success: function(a) {
                    if (a.confirm) {
                        var i = "";
                        i += e.getNetAddresss(t.api), i += "&order_id=" + o.data.orderPayId, e._getNetWork({
                            url: i,
                            success: function(e) {
                                1 == (e = e.data).result ? (o.triggerEvent("ConfrimOrderNotification", "pay"), wx.showToast({
                                    icon: "success",
                                    title: "".concat(r, "成功"),
                                    duration: 1e3
                                })) : wx.showToast({
                                    icon: "none",
                                    title: e.msg,
                                    duration: 1e3
                                });
                            },
                            fail: function(e) {
                                console.log(e);
                            }
                        });
                    }
                }
            });
        },
        onClose: function() {
            this.setData({
                showQrcode: !1
            });
        },
        _checklogistics: function(e, t) {
            console.log(e, t), 0 == e.is_all_send_goods ? wx.navigateTo({
                url: "/packageA/member/order/logistics/logistics?id=" + e.id + "&api=" + t.api
            }) : wx.navigateTo({
                url: "/packageE/multiplePackages/multiplePackages?id=" + e.id + "&api=" + t.api
            });
        },
        getRuruen: function(t, a) {
            var r = this, o = e.getNetAddresss(t.api);
            o += "&order_id=" + a.id, e._getNetWork({
                url: o,
                success: function(e) {
                    var t = e.data;
                    1 == t.result ? (wx.showToast({
                        title: t.msg,
                        icon: "none",
                        duration: 1500
                    }), r.triggerEvent("ConfrimOrderNotification")) : wx.showToast({
                        icon: "none",
                        title: t.msg,
                        duration: 1e3
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        _deleteOrder: function(e, t, a) {
            var r = this;
            wx.showModal({
                title: "提示",
                content: "确定删除此订单?",
                success: function(o) {
                    if (o.confirm) {
                        var i = r.data.datasource;
                        i.splice(a, 1), r.setData({
                            datasource: i
                        }), r._sentRequest(t.api, "&order_id=" + e.id, !1);
                    }
                }
            });
        },
        _sentRequest: function(t, a, r) {
            var o = e.getNetAddresss(t);
            o += a, e._getNetWork({
                url: o,
                success: function(e) {
                    var t = e.data;
                    1 == t.result ? wx.showToast({
                        title: t.msg,
                        icon: "none",
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1500);
                        }
                    }) : wx.showToast({
                        icon: "none",
                        title: t.msg,
                        duration: 1e3
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        _comment: function(e, t) {
            wx.navigateTo({
                url: "/packageB/comment/comment?order=" + JSON.stringify(e || {})
            });
        },
        _toPay: function(e, t) {
            wx.navigateTo({
                url: "/packageD/buy/orderPay/orderPay?order_id=" + e.id + "&status=1&api=" + t.api
            });
        },
        _toRefundDetail: function(e, t) {
            wx.navigateTo({
                url: "/packageD/member/myOrder/Aftersales/Aftersales?refund_id=" + e.refund_id
            });
        },
        _toRefund: function(e, t) {
            "snatch_regiment_refund" == t.value ? wx.navigateTo({
                url: "/packageD/member/myOrder/refund/refund?order_id=" + e.id + "&type=3"
            }) : wx.navigateTo({
                url: "/packageD/member/myOrder/refund/refund?order_id=" + e.id + "&type=1"
            });
        },
        _cancleOrder: function(e, t, a) {
            var r = this;
            wx.showModal({
                title: "提示",
                content: "确定取消此订单?",
                success: function(o) {
                    if (o.confirm) {
                        var i = r.data.datasource;
                        i.splice(a, 1), r.setData({
                            datasource: i
                        }), r._sentRequest(t.api, "&order_id=" + e.id, !1);
                    }
                }
            });
        },
        _confirmOrder: function(t, a) {
            var r = this, o = e.getNetAddresss(a.api);
            o += "&order_id=" + t.id, wx.showModal({
                title: "提示",
                content: "您确定收到货物?",
                success: function(a) {
                    a.confirm && e._getNetWork({
                        url: o,
                        success: function(e) {
                            var a = e.data;
                            1 == a.result ? r.triggerEvent("ConfrimOrderNotification", t.id) : wx.showToast({
                                icon: "none",
                                title: a.msg,
                                duration: 1e3
                            });
                        },
                        fail: function(e) {
                            console.log(e);
                        }
                    });
                }
            });
        },
        _cashPayOrder: function(e, t) {
            var a = this;
            wx.showModal({
                title: "提示",
                content: "确定此订单已付款?",
                success: function(r) {
                    r.confirm && a._sentRequest(t.api, "&order_id=" + e.id + "&order_pay_id=" + a.data.order_pay_id, !1);
                }
            });
        },
        _verification: function(e, t) {
            wx.navigateTo({
                url: "/packageD/member/myOrder/orderVerification/orderVerification?order_id=" + e.id + "&api=" + t.api
            });
        },
        _verificationCash: function(e, t) {
            var a = this;
            wx.showModal({
                title: "提示",
                content: "确定此订单已付款?",
                success: function(r) {
                    r.confirm && a._sentRequest(t.api, "&order_id=" + e.id + "&order_pay_id=" + a.data.order_pay_id, !1);
                }
            });
        },
        _payMoney: function(t, a) {
            var r = this;
            wx.showModal({
                title: "提示",
                content: "确认支付该订单?",
                success: function(t) {
                    if (t.confirm) {
                        var o = "";
                        "supplier" == r.data.orderType || "subsidiary" == r.data.orderType ? (o += e.getNetAddresss(a.api), 
                        o += "&order_id=" + r.data.orderPayId) : (o += e.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.pay"), 
                        o += "&order_id=" + r.data.orderPayId), e._getNetWork({
                            url: o,
                            success: function(e) {
                                var t = e.data;
                                1 == t.result ? (r.triggerEvent("ConfrimOrderNotification", "pay"), wx.showToast({
                                    icon: "success",
                                    title: "支付成功",
                                    duration: 1e3
                                })) : wx.showToast({
                                    icon: "none",
                                    title: t.msg,
                                    duration: 1e3
                                });
                            },
                            fail: function(e) {
                                console.log(e);
                            }
                        });
                    }
                }
            });
        },
        _getCompany: function() {
            var t = this, a = "";
            "supplier" == t.data.orderType ? a += e.getNetAddresss("plugin.supplier.frontend.order.express-company") : "subsidiary" == t.data.orderType ? a += e.getNetAddresss("plugin.subsidiary.frontend.order.express-company") : a += e.getNetAddresss("plugin.store-cashier.frontend.store.center.sendOrder"), 
            a += "&order_id=" + t.data.orderPayId, e._getNetWork({
                url: a,
                success: function(a) {
                    var r = a.data;
                    if (1 == r.result) {
                        t.setData({
                            options: r.data.express_companies
                        });
                        var o = t.data.options.map(function(e) {
                            return e.name;
                        });
                        e._isTextEmpty(r.data.jurisdiction_set) || t.setData({
                            jurisdiction_set: r.data.jurisdiction_set
                        }), t.setData({
                            columns: o,
                            addresseeInfo: r.data.address
                        });
                    }
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        _deliverGoodsCancel: function(t, a) {
            var r = this;
            wx.showModal({
                title: "提示",
                content: "确定取消发货?",
                success: function(t) {
                    if (t.confirm) {
                        var o = "";
                        "supplier" == r.data.orderType || "subsidiary" == r.data.orderType ? (o += e.getNetAddresss(a.api), 
                        o += "&order_id=" + r.data.orderPayId) : "auction" == r.data.orderType ? (o += e.getNetAddresss("plugin.auction.api.order-operation.cancel-send"), 
                        o += "&order_id=" + r.data.orderPayId) : (o += e.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.cancel-send"), 
                        o += "&order_id=" + r.data.orderPayId), e._getNetWork({
                            url: o,
                            success: function(e) {
                                var t = e.data;
                                1 == t.result ? (r.triggerEvent("ConfrimOrderNotification", "pay"), wx.showToast({
                                    icon: "success",
                                    title: "取消发货成功",
                                    duration: 1e3
                                })) : wx.showToast({
                                    icon: "none",
                                    title: t.msg,
                                    duration: 1e3
                                });
                            },
                            fail: function(e) {
                                console.log(e);
                            }
                        });
                    }
                }
            });
        },
        _collectGoods: function(t, a) {
            var r = this;
            wx.showModal({
                title: "提示",
                content: "确认收货?",
                success: function(t) {
                    if (t.confirm) {
                        var o = "";
                        "supplier" == r.data.orderType || "subsidiary" == r.data.orderType || "pickup_card" == r.data.orderType ? (o += e.getNetAddresss(a.api), 
                        o += "&order_id=" + r.data.orderPayId) : (o += e.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.receive"), 
                        o += "&order_id=" + r.data.orderPayId), e._getNetWork({
                            url: o,
                            success: function(e) {
                                var t = e.data;
                                1 == t.result ? (r.triggerEvent("ConfrimOrderNotification", "pay"), wx.showToast({
                                    icon: "success",
                                    title: "收货成功",
                                    duration: 1e3
                                })) : wx.showToast({
                                    icon: "none",
                                    title: t.msg,
                                    duration: 1e3
                                });
                            },
                            fail: function(e) {
                                console.log(e);
                            }
                        });
                    }
                }
            });
        },
        _closeOrderPay: function(t, a) {
            var r = this;
            wx.showModal({
                title: "提示",
                content: "确定关闭订单?",
                success: function(t) {
                    if (t.confirm) {
                        var o = "";
                        "supplier" == r.data.orderType || "subsidiary" == r.data.orderType ? (o += e.getNetAddresss(a.api), 
                        o += "&order_id=" + r.data.orderPayId) : (o += e.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.close"), 
                        o += "&order_id=" + r.data.orderPayId, o += "&shop_id=null"), e._getNetWork({
                            url: o,
                            success: function(e) {
                                1 == (e = e.data).result ? (r.triggerEvent("ConfrimOrderNotification", "pay"), wx.showToast({
                                    icon: "success",
                                    title: "关闭订单成功",
                                    duration: 1e3
                                })) : wx.showToast({
                                    icon: "none",
                                    title: e.msg,
                                    duration: 1e3
                                });
                            },
                            fail: function(e) {
                                console.log(e);
                            }
                        });
                    }
                }
            });
        },
        _evaluate: function(e, t) {
            wx.navigateTo({
                url: "/packageD/member/myOrder/DeliveryEvaluate/DeliveryEvaluate?order_id=" + e.order_id + "&api=" + t.api + "&name=distributor"
            });
        },
        _truckList: function(e, t) {
            wx.navigateTo({
                url: "/packageD/member/myOrder/truckList/truckList?order_id=" + t.id
            });
        },
        _checkInvoice: function(e, t) {
            wx.navigateTo({
                url: "/packageD/member/myOrder/invoice/invoice?order_id=" + t.id
            });
        },
        numberNamebtn: function(e) {
            var t = e.detail.value;
            this.setData({
                numberName: t
            });
        },
        sendGoogs: function(t) {
            var a = this;
            if (t && "confirm" !== t.detail) this.setData({
                dialogVisible: !1
            }), this.triggerEvent("stoprefresh", !1); else {
                var r = this, o = function(e) {
                    a.setData({
                        sendGoogsFail: {
                            show: !0,
                            msg: e
                        },
                        dialogVisible: !1
                    });
                };
                if ("supplier" == this.data.orderType) {
                    var i = "";
                    i += e.getNetAddresss("plugin.supplier.frontend.order.send");
                    var s = {
                        order_id: r.data.orderPayId,
                        express_code: r.data.expressName.value,
                        express_company_name: r.data.expressName.name,
                        express_sn: r.data.numberName
                    };
                    e._postNetWork({
                        url: i,
                        showToastIn: !1,
                        data: s,
                        success: function(e) {
                            var t = e.data;
                            console.log("msg=", t), 1 == t.result ? (r.setData({
                                dialogVisible: !1
                            }), r.triggerEvent("stoprefresh", !1), r.triggerEvent("ConfrimOrderNotification", "pay"), 
                            wx.showToast({
                                icon: "success",
                                title: "发货成功",
                                duration: 1e3
                            })) : o(t.msg);
                        },
                        fail: function(e) {}
                    });
                } else if ("subsidiary" == this.data.orderType) {
                    var n = "";
                    n += e.getNetAddresss("plugin.subsidiary.frontend.order.send");
                    var d = {
                        order_id: r.data.orderPayId,
                        express_code: r.data.expressName.value,
                        express_company_name: r.data.expressName.name,
                        express_sn: r.data.numberName
                    };
                    e._postNetWork({
                        url: n,
                        showToastIn: !1,
                        data: d,
                        success: function(e) {
                            var t = e.data;
                            1 == t.result ? (r.setData({
                                dialogVisible: !1
                            }), r.triggerEvent("stoprefresh", !1), r.triggerEvent("ConfrimOrderNotification", "pay"), 
                            wx.showToast({
                                icon: "success",
                                title: "发货成功",
                                duration: 1e3
                            })) : o(t.msg);
                        },
                        fail: function(e) {}
                    });
                } else if ("auction" == this.data.orderType) {
                    var c = "";
                    c += e.getNetAddresss("plugin.auction.api.order-operation.send");
                    var u = {
                        order_id: r.data.orderPayId,
                        express_code: r.data.expressName.value,
                        express_company_name: r.data.expressName.name,
                        express_sn: r.data.numberName
                    };
                    e._postNetWork({
                        url: c,
                        showToastIn: !1,
                        data: u,
                        success: function(e) {
                            var t = e.data;
                            1 == t.result ? (r.setData({
                                dialogVisible: !1
                            }), r.triggerEvent("stoprefresh", !1), r.triggerEvent("ConfrimOrderNotification", "pay"), 
                            wx.showToast({
                                icon: "success",
                                title: "发货成功",
                                duration: 1e3
                            })) : o(t.msg);
                        },
                        fail: function(e) {}
                    });
                } else {
                    var l = "";
                    l += e.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.send"), 
                    l += "&order_id=" + r.data.orderPayId, l += "&express_code=" + r.data.expressName.value, 
                    l += "&express_company_name=" + r.data.expressName.name, l += "&express_sn=" + r.data.numberName, 
                    e._getNetWork({
                        url: l,
                        success: function(e) {
                            var t = e.data;
                            1 == t.result ? (console.log("result=", t.result), r.triggerEvent("ConfrimOrderNotification", "pay"), 
                            wx.showToast({
                                icon: "success",
                                title: "发货成功",
                                duration: 1e3
                            }), r.setData({
                                dialogVisible: !1
                            })) : o(t.msg);
                        },
                        fail: function(e) {}
                    });
                }
            }
        },
        colseSendGoogsFailPopup: function() {
            this.setData({
                "sendGoogsFail.show": !1
            });
        },
        seleRegional: function() {
            this.setData({
                dateshow_1: !0
            });
        },
        onCancelbtn: function() {
            this.setData({
                dateshow_1: !1
            });
        },
        onConfirmbtn: function(e) {
            var t = e.detail.index, a = e.detail.value, r = this.data.options;
            this.setData({
                dateshow_1: !1,
                regional: a,
                expressName: r[t]
            });
        },
        noop: function() {},
        confirmHotelOrder: function(t, a) {
            var r = "";
            r += e.getNetAddresss(t), r += "&order_id=" + a, e._getNetWork({
                url: r,
                success: function(e) {
                    var t = e.data;
                    t.result, wx.showToast({
                        icon: "none",
                        title: t.msg,
                        duration: 1e3
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        copyorderbtn: function(e) {
            var t = e.currentTarget.dataset.copydata;
            wx.setClipboardData({
                data: t || "",
                success: function(e) {
                    wx.showToast({
                        icon: "none",
                        title: "复制成功",
                        duration: 1e3
                    });
                }
            });
        }
    }
});